package com.xyzk.diagnose.activity.adapter;

import java.util.HashMap;
import java.util.List;

import com.xyzk.diagnose.R;
import com.xyzk.diagnose.TApplication;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BluetoothDeviceAdapter extends BaseAdapter{
	private List<HashMap<String,String>> data;

	public BluetoothDeviceAdapter(List<HashMap<String,String>> listdata) {
		data = listdata;
	}

	@Override
	public int getCount() {
		return data == null ? null : data.size();
	}
	@Override
	public HashMap<String,String> getItem(int position) {
		return data == null ? null : data.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh;
		if(convertView == null){
			convertView = View.inflate(TApplication.getContext(),R.layout.activity_bluetooth_item,null);
			vh = new ViewHolder();
			vh.deviceName = (TextView)convertView.findViewById(R.id.bluetooth_connect_listitem_name);
			vh.deviceStatus = (TextView)convertView.findViewById(R.id.bluetooth_connect_listitem_connectstatus);
			vh.deviceMac = (TextView)convertView.findViewById(R.id.bluetooth_connect_listitem_macaddr);
			vh.devicePair = (TextView)convertView.findViewById(R.id.bluetooth_connect_listitem_pair);
			convertView.setTag(vh);
		}else{
			vh = (ViewHolder) convertView.getTag();
		}
		vh.deviceName.setText((String)data.get(position).get("deviceName"));
		vh.deviceStatus.setText((String)data.get(position).get("deviceStatus"));
		vh.deviceMac.setText((String)data.get(position).get("deviceMac"));
		vh.devicePair.setText((String)data.get(position).get("devicePair"));
		return convertView;
	}

	public class ViewHolder{
		public TextView  deviceName;  	//设备名称
		public TextView  deviceStatus;	//连接状态提示
		public TextView  deviceMac;	    //设备mac地址
		public TextView  devicePair;    //设备配对状态
	}
}
